﻿using SIG.Model.Store;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SIG.Model.Mapping
{
    public class OrderDetailMap: EntityTypeConfiguration<OrderDetail>
    {
        public OrderDetailMap()
        {
            this.HasKey(p => p.Id);
            this.ToTable("OrderDetailSet");
            this.Property(p => p.Id)
                .HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);


            this.Property(p => p.GoodsId).IsRequired();
            this.Property(p => p.OrderId).IsRequired();
            this.Property(p => p.Quantity).IsRequired();
            this.Property(p => p.UnitPrice).HasPrecision(18,2).IsRequired();
        


            this.HasRequired(p => p.Goods)
              .WithMany(h => h.OrderDetails)
              .HasForeignKey(p => p.GoodsId);

            this.HasRequired(p => p.Order)
             .WithMany(h => h.OrderDetails)
             .HasForeignKey(p => p.OrderId).WillCascadeOnDelete(true);     

     }
   }
}
